<?php
require_once dirname(dirname(__FILE__)) . '/config/config.php';
require_once DOCUMENT_ROOT . DIR_SHARED_DAO . "dao_movie.php";
require_once DOCUMENT_ROOT . DIR_SHARED_DAO . "dao_movie_status.php";
require_once DOCUMENT_ROOT . DIR_SHARED_LIBRARIES . 'lib_sql_convert.php';


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of api_security
 *
 * @author Thien
 */
class api_movies {
    
    public static function save_movie($movie_id, $title, $status_id, $description, $poster) {
        $dao_movie = new dao_movie();
        return $dao_movie->save($movie_id, lib_sql_convert::get_converted_string($title), 
                $status_id, lib_sql_convert::get_converted_string($description), $poster);
    }
    
    public static function delete_movie($movie_id) {
        $dao_movie = new dao_movie();
        return $dao_movie->delete($movie_id);
    }
    
    public static function get_movie_by_id($movie_id) {
        $dao_movie = new dao_movie();
        return $dao_movie->get_by_id($movie_id);
    }
    
    public static function get_all_movies() {
        $dao_movie = new dao_movie();
        return $dao_movie->get_all();
    }
    
    public static function get_all_movies_with_now_showing_and_number($entry_number) {
        $dao_movie = new dao_movie();
        $status_id = 2; //for now showing
        return $dao_movie->get_all_by_status_id($status_id, $entry_number);
    }
    
    public static function get_all_movies_with_now_showing() {
        $dao_movie = new dao_movie();
        $status_id = 2; //for now showing
        return $dao_movie->get_all_by_status_id($status_id, 0);
    }
    
    public static function get_all_movies_with_comming_soon_and_number($entry_number) {
        $dao_movie = new dao_movie();
        $status_id = 1; //for comming soon
        return $dao_movie->get_all_by_status_id($status_id, $entry_number);
    }
    
    public static function get_all_movies_with_comming_soon() {
        $dao_movie = new dao_movie();
        $status_id = 1; //for comming soon
        return $dao_movie->get_all_by_status_id($status_id, 0);
    }
    
    public static function get_all_movie_statuses() {
        $dao_movie_status = new dao_movie_status();
        return $dao_movie_status->get_all();
    }
    
    public static function get_default_movie_statuses() {
        $dao_movie_status = new dao_movie_status();
        $status = $dao_movie_status->get_first();
        if (!empty($status['name'])) {
            return $status['name'];
        }
        return "";
    }
    
    public static function get_status_id_from_name($name) {
        $dao_movie_status = new dao_movie_status();
        $status = $dao_movie_status->get_id_by_name($name);
        return $status['id'];
    }
    
    public static function validate_movie_fields($title, $description, $poster) {
        $error_show = "";
        if (empty($title)) {
            $error_show .= "<li>Please fill Title.</li>";
        }
        if (empty($description)) {
            $error_show .= "<li>Please fill Description.</li>";
        }
        if (empty($poster)) {
            $error_show .= "<li>Please upload a Poster.</li>";
        }
        return $error_show;
    }
    
}
